﻿/// <summary>
///     获取当前登录会员的Session
/// </summary>
/// <returns>
///     null        当前用户未登录
///     MemberModel 当前登录用户对象
/// </returns>
function getSessionMember() {
    var req = new requestCommand(999);
    req.async = false;
    var member = null;
    req.get(function (data) { member = data; });
    return member;
}

function ajaxRequest(url) {
    this.async = true;
    this.url = url;
    this.dataType = 'json';
    this.get = function (success_callback) { return __get(this, success_callback); };
    this.post = function (postData, success_callback) { return __post(this, postData, success_callback); };

    function __get(request, success_callback) {
        jQuery.ajax({
            url: request.url,
            type: 'get',
            async: request.async,
            dataType: request.dataType,
            success: function (r) { return success_callback(r); }
        });
    }

    function __post(request, postData, success_callback) {
        jQuery.ajax({
            url: request.url,
            type: 'post',
            async: request.async,
            data: postData,
            dataType: request.dataType,
            success: function (r) { return success_callback(r); }
        });
    }
}

function requestCommand(cmd, cmdArgs) {
    this.command = cmd;
//    this.langID = 2052;
    this.async = true;

    this.url = "/xmlhttpgate.aspx?cmd=" + this.command + "&random=" + new Date().toLocaleString();
    if (cmdArgs != null && typeof cmdArgs != "undefined") {
        if (cmdArgs.length > 0) {
            if (cmdArgs.substring(0, 1) == "&")
                this.url += cmdArgs;
            else
                this.url += "&" + cmdArgs;
        }
    }

    this.request = new ajaxRequest(this.url);
    this.request.async = this.async;

    this.get = function (success_callback) { this.request.async = this.async; return this.request.get(success_callback); };
    this.post = function (postData, success_callback) { this.request.async = this.async; return this.request.post(postData, success_callback); };
}